<template>
  <div class="xtx-goods-page" v-if="good.categories">
    <div class="container">
      <!-- 面包屑 -->
      <XtxBread separator="/">
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <XtxBreadItem to="/">{{ good.categories[1].name }}</XtxBreadItem>
        <XtxBreadItem to="/">{{ good.categories[0].name }}</XtxBreadItem>
        <XtxBreadItem to="/">{{ good.name }}</XtxBreadItem>
      </XtxBread>
      <!--------------- 商品信息 ------------------>
      <div class="goods-info">
        <!-- 图片预览区 -->
        <div class="media">
          <GoodsImg :imgList="good.mainPictures" />
          <GoodsSales />
        </div>
        <!-- 商品信息区 -->
        <div class="spec">
          <GoodsName />
          <GoodsSku :goods="good" @change="selSku" />
          <XtxNumBox :max="good.inventory" v-model="buyNum" />
          <XtxButton
            @click="addCat"
            style="margin-top: 20px"
            size="large"
            type="primary"
          >
            加入购物车
          </XtxButton>
        </div>
      </div>
      <!---------------- 商品详情 ------------------>
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品+评价 -->
          <div class="goods-tabs">
            <!-- 详情图片列表 -->
            <img
              v-imgLazy="url"
              v-for="url in good.details.pictures"
              :key="url"
            />
          </div>
        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside"></div>
      </div>
    </div>
  </div>
</template>

<script>
// import { findGoods } from '@/api/goods'
// import { useRoute } from 'vue-router'
// import { ref, provide } from 'vue'

import GoodsImg from './components/goods-image.vue'
import GoodsName from './components/goods-name.vue'
import GoodsSales from './components/goods-sales.vue'

import { getGoodInfo, selSkuInfo, addCats } from '@/hook/Good'

export default {
  name: 'XtxGoodsPage',
  components: {
    GoodsImg,
    GoodsName,
    GoodsSales
  },
  setup () {
    // 功能一：获取商品信息
    const { buyNum, good } = getGoodInfo()

    // 功能二：存储sku信息
    const { selSku, currSel } = selSkuInfo(good)

    // 功能三：加入购物车
    const { addCat } = addCats(good, buyNum, currSel)

    return { good, selSku, buyNum, addCat, currSel }
  }
}
</script>

<style scoped lang='less'>
.goods-info {
  min-height: 600px;
  background: #fff;
  display: flex;
  // 新增样式
  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }
  .spec {
    flex: 1;
    padding: 30px 30px 30px 0;
  }
}
.goods-footer {
  display: flex;
  margin-top: 20px;
  .goods-article {
    width: 940px;
    margin-right: 20px;
  }
  .goods-aside {
    width: 280px;
    min-height: 1000px;
    background: #fff;
  }
}
.goods-tabs {
  min-height: 600px;
  background: #fff;
  img {
    width: 100%;
  }
}
.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}
</style>
